<template>
  <div class="app">
    <!-- 将获取到的数据进行计算 -->
<!--    <el-table :data="tableData.slice((currentPage-1)*PageSize,currentPage*PageSize)" style="width: 100%">-->
<!--      <el-table-column prop="date" label="日期" width="180"></el-table-column>-->
<!--      <el-table-column prop="name" label="姓名" width="180"></el-table-column>-->
<!--      <el-table-column prop="address" label="地址"></el-table-column>-->
<!--    </el-table>-->
    <el-table
        :data="tableData.slice((currentPage-1)*PageSize,currentPage*PageSize)"
        style="width: 100%">
      <el-table-column
          label="日期"
          width="180">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </template>
      </el-table-column>
      <el-table-column
          label="姓名"
          width="180">
        <template slot-scope="scope">
          <el-popover trigger="hover" placement="top">
            <p>姓名: {{ scope.row.name }}</p>
            <p>账号: {{ scope.row.account }}</p>
            <div slot="reference" class="name-wrapper">
              <el-tag size="medium">{{ scope.row.name }}</el-tag>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
              size="mini"
              type="danger"
              @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination @size-change="handleSizeChange"
                   @current-change="handleCurrentChange"
                   :current-page="currentPage"
                   :page-sizes="pageSizes"
                   :page-size="PageSize" layout="total, sizes, prev, pager, next, jumper"
                   :total="totalCount">
    </el-pagination>

    <el-button @click="drawer = true" type="primary" style="margin-left: 16px;">
      点我打开
    </el-button>

    <el-drawer
        title="我是标题"
        :visible.sync="drawer"
        :with-header="false">
      <span>我来啦!</span>
    </el-drawer>
  </div>
</template>

<script>
export default {
  name: "fenye",
  data(){
    return {
    userid:{},
      drawer: false,
      tableData:[],
      // 默认显示第几页
      currentPage:1,
      // 总条数
      totalCount:1,
      // 个数选择器
      pageSizes:[1,2,3,4],
      // 默认每页显示的条数
      PageSize:2,
    }
  },
  methods:{
    del(id){
      this.$axios.delete("/api/user/delete/"+id).then(res => {
        console.log(res);
        if(res.data.status===1){
          this.$message.success(res.data.msg);
          this.zzz();
        }
      })
    },
    zzz(){
      this.$axios.get("/api/user/Jurisdiction").then(res => {
        console.log(res);
        if(res.data.status===1){
          this.tableData=res.data.data;
        }
      });
    },

    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
    getTabData(){
      //此处直接赋值代替发Ajax获取数据
      this.tableData=[{
        date: '',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      },
        {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      },
        {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      },
        {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      },
        {
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      },
        {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      },
        {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      },
        {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }]

      this.totalCount=this.tableData.length

    },
    // 分页
    // 每页显示的条数
    handleSizeChange(val) {
      // 改变每页显示的条数
      this.PageSize=val
      // 在改变每页显示的条数时，要将页码显示到第一页
      this.currentPage=1
    },
    // 显示第几页
    handleCurrentChange(val) {
      // 改变默认的页数
      this.currentPage=val
    },
  },
  created:function(){
    this.getTabData();
    // this.$axios.get("/api/user/Jurisdiction").then(res => {
    //   console.log(res);
    //   if(res.data.status===1){
    //     this.tableData=res.data.data;
    //   }
    // });
    this.zzz();
  }

}
</script>

<style scoped>

</style>